package com.ruoyi.web.controller.zhuangxiucontroller.shopController;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.zhuangxiumain.shopMain.BrandInfo;
import com.ruoyi.system.service.zhaungxiuservice.shopService.BrandInfoService;
import com.ruoyi.system.service.zhaungxiuservice.shopService.SupplierInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@Api(value = "品牌信息接口", tags = {"品牌信息接口"})
@RestController
@RequestMapping("/shopping/brandinfobi")
public class BrandInfoController extends BaseController {
    @Autowired(required = false)
    private BrandInfoService brandInfoService;

    @Autowired(required = false)
    private TokenService tokenService;

    @Autowired(required = false)
    private SupplierInfoService supplierInfoService;

    /**
     * 查询品牌信息列表
     */
    @ApiResponses({@ApiResponse(code = 200, message = "正常", response = BrandInfo.class)})
    @ApiOperation(value = "查询品牌信息列表")
    @PreAuthorize("@ss.hasPermi('shopping:brandinfo:listbi')")
    @GetMapping("/listbi")
    public TableDataInfo listbi(BrandInfo brandInfo)
    {

//        SupplierInfo supplierInfo = new SupplierInfo();
//        Integer supplierId = supplierInfo.getSupplierId();
//        SupplierInfo supplierInfo1 = supplierInfoService.selectSupplierInfoById(supplierId);
//        System.err.println("************" + supplierInfo1);

        startPage();
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        Long userId = loginUser.getUser().getUserId();
        System.err.println("=================="+userId);

        brandInfo.setUserId(userId);
        List<BrandInfo> list = brandInfoService.selectBrandInfoList(brandInfo);
        return getDataTable(list);
    }




    /**
     * 获取品牌信息详细信息
     */
    @ApiResponses({@ApiResponse(code = 200, message = "正常", response = BrandInfo.class)})
    @ApiOperation(value = "获取品牌信息详细信息")
    @PreAuthorize("@ss.hasPermi('shopping:brandinfo:querybi')")
    @GetMapping(value = "/{brandId}")
    public AjaxResult getInfo(@PathVariable("brandId") Integer brandId)
    {
        return AjaxResult.success(brandInfoService.selectBrandInfoById(brandId));
    }

    /**
     * 新增品牌信息
     */
    @ApiResponses({@ApiResponse(code = 200, message = "正常", response = BrandInfo.class)})
    @ApiOperation(value = "新增品牌信息")
    @PreAuthorize("@ss.hasPermi('shopping:brandinfo:addbi')")
    @Log(title = "品牌信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BrandInfo brandInfo)
    {
        Integer numsupper = brandInfo.getNumsupper();
        brandInfo.setSupplierId(numsupper);
        brandInfo.setBrandStatus(0);  //1禁止，0启用
        brandInfo.setModifiedTime(new Date());
        brandInfoService.insertBrandInfo(brandInfo);
        return AjaxResult.success("操作成功");
    }

    /**
     * 修改品牌信息
     */
    @ApiResponses({@ApiResponse(code = 200, message = "正常", response = BrandInfo.class)})
    @ApiOperation(value = "修改品牌信息")
    @PreAuthorize("@ss.hasPermi('shopping:brandinfo:editbi')")
    @Log(title = "品牌信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BrandInfo brandInfo)
    {
        return toAjax(brandInfoService.updateBrandInfo(brandInfo));
    }

    //状态修改
    @ApiResponses({@ApiResponse(code = 200, message = "正常", response = BrandInfo.class)})
    @ApiOperation(value = "状态修改")
    @PreAuthorize("@ss.hasPermi('shopping:brandinfo:editStatus')")
    @Log(title = "修改状态", businessType = BusinessType.UPDATE)
    @PutMapping("/editStatus")
    public AjaxResult changeStatus(@RequestBody BrandInfo brandInfo){
        return toAjax(brandInfoService.changeStatus(brandInfo));
    }

    /**
     * 删除品牌信息
     */
    @ApiResponses({@ApiResponse(code = 200, message = "正常", response = BrandInfo.class)})
    @ApiOperation(value = "删除品牌信息")
    @PreAuthorize("@ss.hasPermi('shopping:brandinfo:removebi')")
    @Log(title = "品牌信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{brandIds}")
    public AjaxResult remove(@PathVariable Integer[] brandIds)
    {
        return toAjax(brandInfoService.deleteBrandInfoByIds(brandIds));
    }

}
